from typing import List


class Solution:
    def minOperations(self, nums: List[int]) -> int:
        now = 0
        ans = 0
        for num in nums:
            if num > now:
                now = num
            else:
                ans += (now + 1 - num)
                now += 1
        return ans


if __name__ == "__main__":
    print(Solution().minOperations([1, 1, 1]))  # 3
    print(Solution().minOperations([1, 5, 2, 4, 1]))  # 14
    print(Solution().minOperations([8]))  # 0
